#ifndef __LIBMDM_3J4BCHU9
#define __LIBMDM_3J4BCHU9

#include <pthread.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include "cms_common.h"
//#ifdef DBUS_OBJECT_NOTIFY
#include "cms_msg.h"
#include "cms_event.h"
//#endif


/*Definitions for parameter attribute*/
#define PARAMETER_ATTR_READONLY			(1 << 0)
#define PARAMETER_ATTR_NOTIFY			((1 << 1)|(1 << 2))	/*use for notify off*/
#define PARAMETER_ATTR_ACTIVENOTIFY		(1 << 1)
#define PARAMETER_ATTR_PASSIVENOTIFY		(1 << 2)
#define PARAMETER_ATTR_CONFIG			(1 << 3)				/*means this parameter needs to be saved to config.xml*/
#define PARAMETER_ATTR_DEFAULTVALUE		(1 << 4)				/*only run time use, not store at config.xml and add at sysdef.xml, if yes, this parameter has default value*/
#define PARAMETER_ATTR_DEFAULTATTR		(1 << 5)				/*same with PARAMETER_ATTR_DEFAULTVALUE*/
#define PARAMETER_ATTR_FIX_BITS			((1 << 0) | (1 << 3) | (1 << 4) | (1 << 5)) /*fixed bit, can't modify. include CONFIG/READONLY/DEFAULTVALUE/DEFAULTATTR*/
#define PARAMETER_ATTR_NO_MALLOC		(1 << 6)
#define ATTR_HIDEFROMACS					(1 << 7)
#define PARAMETER_ATTR_NOCONFIG			(1 << 16)
#define PARAMETER_ATTR_HEX_VALUE			(1 << 15)				//store hex value
#define PARAMETER_ATTR_ACTIVE_UNSUPPORT	(1 << 17)			/*not support cwmp notify set as active(2)*/



/*Definitions for node attribute*/
#define ATTR_OBJECTNODE		(1 << 0)		/*run time/compiler time both use, no store at xml*/
#define ATTR_INDEXNODE		(1 << 1)		/*run time use, compiler time mark, store both xml*/
#define ATTR_INDEXCHILD		(1 << 2)		/*compiler time use, no store at xml*/
#define ATTR_NODECONFIGURED	(1 << 3)		/*run time use, no store at xml, means this node has been configured and need to save*/
#define ATTR_ALWAYSACTIVE	(1 << 4)		/*for some special case, ex. tr069, the index child nodes need to active at default
											run time/compiler time both use, no store at xml*/
#define ATTR_WRITABLE 		(1 << 5)
#define ATTR_NO_STORABLE	(1 << 6)	/*for i node, check i node if can store to xml*/


/*
remove ATTR_NODENEEDSAVE, every node need to be save to config.xml, even though only non-configured
parameters have been configured.
*/
#define LAST_NAME_FOUND	(1 << 31)	/*use name len last bit to check last name or not*/


/*Definitions for parameter ext-attribute (16 ~ 31 bits)*/
/*if your EXTATTR is fix bit(fix bit means user cannot modify at runtime, only modify at sysdef.xml), please add it to PARAMETER_ATTR_FIX_BITS*/
#define PARAMETER_EXT_ATTR_NON_PASSIVENOTIFY (1 << 0)
#define PARAMETER_EXT_ATTR_NON_ACTIVENOTIFY (1 << 1)

/*Definitions for parameter attribute active type*/
#define PARAMETER_ATTR_ACTIVE	1
#define PARAMETER_ATTR_INACTIVE	0

/*Definitions for index object active type*/
#define INDEX_OBJECT_ACTIVE		1
#define INDEX_OBJECT_INACTIVE	0
#define INDEX_OBJECT_INACTIVE_NORESET 2

//#define RDM_ALLOW_DIRECT_WRITE 1
//#define RDM_ALLOW_DIRECT_READ 1

#define PADDING_META_LEN	4
#define BYTE_ALIGNS			8

/* bit mask for object size and calloc counter. */
#define GET_CALLOC_COUNTER_MASK		0xFF000000
#define GET_OBJECT_SIZE_MASK		0x00FFFFFF
#define GET_CALLOC_COUNTER_SHIFT	24

/*Definitions for copy object type, one is copy node to node, one is reset index child object to i node*/
#define COPY_OBJECT_VALUE		1
#define RESET_INDEXCHILD_OBJECT_VALUE	0

#define CMS_XML_KEY     "3458eb34256cde5dfe23ad9124129716"
#define CMS_XML_IV      "65432100000000000000000000123456"

/*wait for db reponse timeout*/
#define DEFAULT_TIMEOUT  6000

typedef enum objActionType_s
{
	CMS_OBJ_ADD,
	CMS_OBJ_DEL,
	CMS_OBJ_SET,
	CMS_OBJ_UNKNOWN
}objActionType_t;

#ifndef boolean
typedef int boolean;
#endif
#define false 0
#define true 1

typedef union unsign_s{
		uint64_t u64;
		uint32_t u32;
		uint16_t u16;
		uint8_t u8;
} unsign_t;

typedef union sign_s{
		int64_t s63;
		int32_t s31;
		int16_t s15;
		int8_t s7;
} sign_t;

typedef struct setParaValue_s{
	void *parameter;
	void *value;
	void *type;
}setParaValue_t;

typedef struct paraValueSettingList_s{
	struct paraValueSettingList_s *prev;
	struct paraValueSettingList_s *next;
	char    parameter[128];
	uint8_t *value;
	uint32_t type;
}paraValueSettingList_t;

typedef struct cms_paramChgList_s{
	struct cms_paramChgList_s *prev;
	struct cms_paramChgList_s *next;
	char    paramName[128];
}cms_paramChgList_t;

typedef struct cms_objDbusNotify_s{
	uint32_t objID;
	uint64_t objIA;
	objActionType_t objAction;
	cms_paramChgList_t *parameterList;
}cms_objDbusNotify_t;


typedef struct parameterValue_s {
		char *name;						/*parameter name*/
		void *value;
		uint32_t type_size;
		union{
			sign_t sign;
			unsign_t unsign;
		}max;
		union{
			sign_t sign;
			unsign_t unsign;
		}min;		
}parameterValue_t;

#define CMS_MAX_PATH_NAME 1024

typedef enum obj_handle_type {
	OBJ_ADD = 1,
	OBJ_DEL,
	OBJ_SET
}obj_handle_type_t;

typedef struct cms_objOff_s{
	uint32_t OID;
	uint64_t OIA;
}cms_objOff_t;

union cms_obj_u{
	cms_objOff_t objOID;
	char pathName[CMS_MAX_PATH_NAME];
};

typedef struct cms_objInfo_s{
	cmsBoolean isPathName; /*false -- OID, true -- name*/
	union cms_obj_u object;
}cms_objInfo_t;

typedef struct cms_multiObjSettingList_s{
	struct cms_multiObjSettingList_s *prev;
	struct cms_multiObjSettingList_s *next;
	obj_handle_type_t type;
	cms_objInfo_t objectInfo;
	paraValueSettingList_t *paramList;
}cms_multiObjSettingList_t;


typedef struct tree_s{
		cmsoffset_t next;				/* Next sibling, the smaller one offset*/
		cmsoffset_t prev;				/* Prev sibling, the larger one offset*/
} tree_t;

typedef struct objectNode_s {
		cmsoffset_t child;				/* Children, always pointer to middle child offset*/
		cmsoffset_t parent;				/* Parent node's offset*/
		union {
			tree_t tree;
			uint32_t	child_count;	/*only for index leaf child number*/
		}sibling;

		cmsoffset_t meta;				/* Parameter meta list offset*/		
		uint32_t attributes;			/*node attribute*/
		uint32_t updateObjFlag;			/*record object update attr*/
		cmsoffset_t name;				/*object name offset*/
		cmsoffset_t object;				/*share memory address offset of object*/
		uint32_t object_size;			/*length of the object*/
		uint32_t config_size;			/*config parameters part's length of the object*/	
//		cmsoffset_t validationFunc;	/*validation function pointer offset*/	
		uint16_t meta_count;			/*Parameter meta number*/
		uint16_t height;				/*for insert node use, now it's for AVL tree*/
		uint32_t priority;				/*for cms_task to order execute oid_function */
}objectNode_t;

typedef struct cmsMutexPack_s{
	pthread_mutex_t lock;
	pthread_mutexattr_t lock_attr;
	//int 	lockShmId;				/*shm to sotre the lock and lock attr*/
	//void *lockShmAddr;			/*shm address of lock shm*/
}cmsMutexPack_t;

typedef struct cmsXmlCb_s {
		int shmId;						/*share memory id*/
		uint32_t shmSize;				/*share memory size*/
		void *baseaddr;					/*attach memory start address*/
		objectNode_t *rootNode;			/*first node*/
		uint32_t objectSize;			/*use to get objectSize*/
		uint32_t objectIndex;			/*use to get index number*/
		objectNode_t *objectNode;		/*use to get node pointer*/
		uint16_t	meta_count;			/*Parameter meta number*/
		char *cmsFileName;				/*store cms name, ex. config.current.cms*/
		char *xmlFileName;				/*store xml name, ex. config.current.xml*/		
		int OID;						/*store current OID of this object*/
		uint64_t IA;					/*store current IA of this object*/
		cmsoffset_t offset;				/*store current object offset of this object*/
		cmsMutexPack_t *cmsMutex;		/*xml lock*/
		void *lockShmAddr;				/*shm address of lock shm*/
		int 	lockShmId;				/*shm to sotre the lock and lock attr*/
#ifdef GC_APPS_CTC
		cmsBoolean srcFromDbus;
#endif
		int readOnly;					/*1: readOnly enable, 0: read and wirte; record current app xml shm authority, if read only, can't modify xml shm*/
}cmsXmlCb_t;

typedef struct cwmp_getObjParaList_s{
	struct cwmp_getObjParaList_s *prev;
	struct cwmp_getObjParaList_s *next;
	char	parameterPath[256];
	boolean writeable;
}cwmp_getObjParaList_t;

typedef struct cwmp_getParaAttrList_s{
	struct cwmp_getParaAttrList_s *prev;
	struct cwmp_getParaAttrList_s*next;
	char	parameterName[256];
	int 	notfiyType;
}cwmp_getParaAttrList_t;

enum cwmp_parameterValue_type{
	CWMP_PARAM_TYPE_UNKNOWN,
	CWMP_PARAM_TYPE_OBJECT,
	CWMP_PARAM_TYPE_MULTIPLE,
	CWMP_PARAM_TYPE_STRING,
	CWMP_PARAM_TYPE_INT,
	CWMP_PARAM_TYPE_UNSINGED_INT,
	CWMP_PARAM_TYPE_BOOLEAN,
	CWMP_PARAM_TYPE_DATATIME,
	CWMP_PARAM_TYPE_BASE64	
};

enum CWMP_RETCODE{	
	CWMP_OK = 0,					//cwmp handle success.
	CWMP_INCOMPLETE_OK = 1,			//cwmp handle success, but apps not yet in effect, need reboot or somethins else.
	
	CWMP_ERROR_UNSUPPORT = 9000,	 //Method not supported
	CWMP_ERROR_REQ_DENIED = 9001, 	//Request denied(no reason specified)
	CWMP_ERROR_INTERNAL  = 9002,   	//Internal error
	CWMP_ERROR_INVALID_ARG = 9003,	//Invalid arguments
	CWMP_ERROR_RES_LEEK = 9004,	 	/*Resources exceeded(when used in association with setParameterValues,
									This MUST not be used to indicate parameters in error)*/
	CWMP_ERROR_PARA_NAME = 9005,  	/*Invalid parameter name(associated with Set/GetParameterValues, 
							 		GetParameterNames, Set/GetParameterAttributes)*/
	CWMP_ERROR_INVALID_TYPE = 9006,	//Invalid parameter type(associated with setParameterValues)
	CWMP_ERROR_INVALID_VALUE = 9007,//Invalid parameter value(associated with setParameterValues)
	CWMP_ERROR_SET_READONLY = 9008, //Attempt to set a non-writable parameter(associated with setParameterValues)
	CWMP_ERROR_REJECTED = 9009,		//Notification request rejected(associated with setParameterAttributes method)

	/*user define*/
	CWMP_ERROR_NOTIFY_UNSUPPORT = 9800, //unsupport modify paramter notify attr as active, the param only support off/passive
	CWMP_ERROR_PARAMETER_NOEXIST = 9801, //paramter not exist
	RESERVED
};



#ifdef XML_SHM_DIRECT_WRITE
int allow_direct_write_xmlShm __attribute__ ((weak)) = 1;
#define cmsXmlAddObjByOID(xmlShmCb,OID,objIA,count, parameter)						cmsXml_addObjectByOIDIA(xmlShmCb,OID,objIA,count, parameter)
#define cmsXmlAddObjByOIDWithParaList(xmlShmCb,OID,objIA, paraList)					cmsXml_addObjectByOIDWithParaList(xmlShmCb, OID,objIA, paraList)
#define cmsXmlAddObjByPathName(xmlShmCb, pathName,count, parameter) 				cmsXml_addObjectByPathName(xmlShmCb, pathName,count, parameter)
#define cmsXmlAddObjByPathNameWithParaList(xmlShmCb, pathName, paraList) 			cmsXml_addObjectByPathNameWithList(xmlShmCb, pathName, paraList)
#define cmsXmlDelObjByOID(xmlShmCb, OID, objIA) 									cmsXml_delObjectByOIDIA(xmlShmCb, OID, objIA)
#define cmsXmlDelObjByPathName(xmlShmCb, pathName) 									cmsXml_delObjectByPathName(xmlShmCb, pathName)
#define cmsXmlSetParameter(xmlShmCb, object, count, parameter)						cmsXml_setParameter(xmlShmCb,object,count,parameter)
#define cmsXmlSetParameterByParaList(xmlShmCb, objOffset, parameterList)			cmsXml_setParameterByParaList(xmlShmCb, objOffset, parameterList)
#define cmsXmlSetParameterNnotify(xmlShmCb, objOffset, parameterList, replyFlag) 			cmsXml_setParameterNnotify(xmlShmCb, objOffset, parameterList, replyFlag)
#define cmsXmlSetOneParameterByOID(xmlShmCb,OID,IA,parameter,type,value)			cmsXml_setOneParameterByOID(xmlShmCb,OID,IA,parameter,type,value)
#define cmsXmlSetOneParameterByObjPath(xmlShmCb,objPath,parameter,type,value)		cmsXml_setOneParameterByPath(xmlShmCb,objPath,parameter,type,value)
#define cmsXmlGetParameter(xmlShmCb, objOffset, count, parameter)					cmsXml_getParameter(xmlShmCb, objOffset, count, parameter)
#define cmsXmlSetParameterAttr(xmlShmCb, object, parameter, attr, isActive)			cmsXml_setParameterAttr(xmlShmCb, object, parameter, attr, isActive)
#define cmsXmlGetParameterAttr(xmlShmCb, objOffset, parameter)						cmsXml_getParameterAttr(xmlShmCb, objOffset, parameter)
#define cmsXmlSetParameterExtAttr(xmlShmCb, object, parameter, flags, type)			cmsXml_setParameterExtAttr(xmlShmCb, object, parameter, flags, type)
#define cmsXmlSave(xmlShmCb)														cmsXml_SaveDirect(xmlShmCb)
#define cmsXmlObjectRestore(xmlShmCb, objOffset)									cmsXml_objectRestore(xmlShmCb, objOffset)
#else
int allow_direct_write_xmlShm __attribute__ ((weak)) = 0;
#define cmsXmlAddObjByOID(xmlShmCb,OID,objIA, count, parameter)						cmsXml_addObjectByOIDIAIndirect(xmlShmCb, OID,objIA, count, parameter)
#define cmsXmlAddObjByOIDNoReply(xmlShmCb,OID,objIA, count, parameter)					cmsXml_addObjectByOIDIAIndirect_noReply(xmlShmCb, OID,objIA, count, parameter)
#define cmsXmlAddObjByOIDWithParaList(xmlShmCb,OID,objIA, parameterList)				cmsXml_addObjectByOIDIWithParaListIndirect(xmlShmCb, OID,objIA, parameterList)
#define cmsXmlAddObjByOIDNnotify(xmlShmCb,OID,objIA, parameterList, replyFlag)			cmsXml_addObjectByOIDNnotify(xmlShmCb,OID,objIA, parameterList, replyFlag)
#define cmsXmlAddObjByOIDWithParaListNoReply(xmlShmCb,OID,objIA, parameterList)		cmsXml_addObjectByOIDIWithParaListIndirect_noReply(xmlShmCb, OID,objIA, parameterList)
#define cmsXmlAddObjByPathName(xmlShmCb,pathName, count, parameter) 					cmsXml_addObjectByPathNameIndirect(xmlShmCb, pathName, count, parameter)
#define cmsXmlAddObjByPathNameNoReply(xmlShmCb,pathName, count, parameter) 			cmsXml_addObjectByPathNameIndirect_noReply(xmlShmCb, pathName, count, parameter)
#define cmsXmlAddObjByPathNameWithParaList(xmlShmCb, pathName, parameterList) 			cmsXml_addObjectByPathNameWithParaList(xmlShmCb, pathName, parameterList)
#define cmsXmlAddObjByPathNameWithParaListNoReply(xmlShmCb, pathName, parameterList) 	cmsXml_addObjectByPathNameWithParaList_noReply(xmlShmCb, pathName, parameterList)
#define cmsXmlAddObjByPathNameNnotify(xmlShmCb, pathName, parameterList, replyFlag) 	cmsXml_addObjectByPathNameNnotify(xmlShmCb, pathName, parameterList, replyFlag)
#define cmsXmlDelObjByOID(xmlShmCb, OID, objIA) 										cmsXml_delObjectByOIDIAIndirect(xmlShmCb, OID, objIA)
#define cmsXmlDelObjByOIDNoReply(xmlShmCb, OID, objIA) 								cmsXml_delObjectByOIDIAIndirect_noReply(xmlShmCb, OID, objIA)
#define cmsXmlDelObjByPathName(xmlShmCb, pathName) 									cmsXml_delObjectByPathNameIndirect(xmlShmCb,  pathName)
#define cmsXmlDelObjByOIDNnotify(xmlShmCb, OID, objIA, replyFlag) 						cmsXml_delObjectByOIDIANnotify(xmlShmCb, OID, objIA, replyFlag)
#define cmsXmlDelObjByPathNameNoReply(xmlShmCb, pathName) 							cmsXml_delObjectByPathNameIndirect_noReply(xmlShmCb,  pathName)
#define cmsXmlDelObjByPathNameNnotify(xmlShmCb, pathName, replyFlag)					cmsXml_delObjectByPathNameNnotify(xmlShmCb, pathName, replyFlag)
#define cmsXmlSetParameter(xmlShmCb, object,count, parameter)							cmsXml_setParameterIndirect(xmlShmCb, object, count, parameter)
#define cmsXmlSetParameterNoReply(xmlShmCb, object,count, parameter)					cmsXml_setParameterIndirect_noReply(xmlShmCb, object, count, parameter)
#define cmsXmlSetParameterByParaList(xmlShmCb, objOffset, parameterList)					cmsXml_setParameterIndirectByParaList(xmlShmCb, objOffset,  parameterList)
#define cmsXmlCwmpSetParam(xmlShmCb, objOffset, parameterList, replyFlag)				cmsXml_cwmpSetParameterNnotify(xmlShmCb, objOffset, parameterList, replyFlag)
#define cmsXmlSetParameterNnotify(xmlShmCb, objOffset, parameterList, replyFlag) 			cmsXml_setParameterNnotify(xmlShmCb, objOffset, parameterList, replyFlag)
#define cmsXmlSetParameterByParaListNoReply(xmlShmCb, objOffset, parameterList)			cmsXml_setParameterIndirectByParaList_noReply(xmlShmCb, objOffset,  parameterList)
#define cmsXmlSetOneParameterByOID(xmlShmCb,OID,IA,parameter,type,value)				cmsXml_setOneParameterByOIDIndirect(xmlShmCb,OID,IA,parameter,type,value)
#define cmsXmlSetOneParameterByObjPath(xmlShmCb,objPath,parameter,type,value)			cmsXml_setOneParameterByPathIndirect(xmlShmCb,objPath,parameter,type,value)
#define cmsXmlGetParameter(xmlShmCb, objOffset, count, parameter)						cmsXml_getParameterIndirect(xmlShmCb, objOffset, count, parameter)
#define cmsXmlSetParameterAttr(xmlShmCb, object, parameter, flags, type)					cmsXml_setParameterAttrIndirect(xmlShmCb, object, parameter, flags, type)
#define cmsXmlSetParameterAttrNoReply(xmlShmCb, object, parameter, flags, type)			cmsXml_setParameterAttrIndirect_noReply(xmlShmCb, object, parameter, flags, type)
#define cmsXmlGetParameterAttr(xmlShmCb, objOffset, parameter)							cmsXml_getParameterAttrIndirct(xmlShmCb, objOffset, parameter)
#define cmsXmlSetParameterExtAttr(xmlShmCb, object, parameter, flags, type)				cmsXml_setParameterExtAttrIndirect(xmlShmCb, object, parameter, flags, type)
#define cmsXmlSave(xmlShmCb)															cmsXml_SaveIndirect(xmlShmCb)
#define cmsXmlSaveNoReply(xmlShmCb)														cmsXml_SaveNoReply(xmlShmCb)
#define cmsXmlUpgradeConf(filePathName)												cmsXml_restoreConfXml(filePathName)
#define cmsXmlRestoreDefault(restoreType)												cmsXml_restoreDefaultXml(restoreType)
/*api for tr069*/
#define cmsXmlSetParameterNotifyAttr(xmlShmCb, pathName, notifyType)      					cmsXml_cwmpSetParameterNotifyAttr(xmlShmCb, pathName, notifyType)
#define cmsXmlGetParametereNotifyAttr(xmlShmCb, pathName, paraAttrList)					cmsXml_cwmpGetParameterNotifyAttr(xmlShmCb, pathName, paraAttrList)
#define cmsXmlSetParameterNotifyAttrByOID(xmlShmCb, OID, IA, paramName, notifyType)      	cmsXml_cwmpSetParameterNotifyAttrByOID(xmlShmCb, OID, IA, paramName, notifyType)
#define cmsXmlGetParameterNotifyAttrByOID(xmlShmCb, OID, IA, paramName, paraAttrList)	cmsXml_cwmpGetParameterNotifyAttrByOID(xmlShmCb, OID, IA, paramName, paraAttrList)
#define cmsXmlFreeNotifyAttrList(paraAttrList) 											cmsXml_cwmpFreeParaNotifyAttrList(paraAttrList)
#define cmsXmlObjectStats(OID, IA, timeout)												cmsXml_ObjectStats(OID, IA, timeout)
/*api for dbus*/
#define cmsXmlSetParameterByParaListWithCmsMsg(xmlShmCb, pReqMsg, objOffset, parameterList)		cmsXml_setParameterIndirectByParaListWithCmsMsg(xmlShmCb, pReqMsg, objOffset,  parameterList)
#define cmsXmlAddObjByOIDWithCmsMsg(xmlShmCb, pReqMsg,OID,objIA, count, parameter)					cmsXml_addObjectByOIDIAIndirectWithCmsMsg(xmlShmCb, pReqMsg, OID,objIA, count, parameter)
#define cmsXmlDelObjByOIDWithCmsMsg(xmlShmCb, pReqMsg, OID, objIA) 								cmsXml_delObjectByOIDIAIndirectWithCmsMsg(xmlShmCb, pReqMsg, OID, objIA)
#define cmsXmlAddObjByOIDWithParaListWithCmsMsg(xmlShmCb,pReqMsg, OID,objIA, parameterList)		cmsXml_addObjectByOIDIWithParaListtWithCmsMsg(xmlShmCb, pReqMsg, OID,objIA, parameterList)
#endif
/*cmsXmlGetParameterByOID/cmsXmlGetParameterByObjPath only for one parameter get value.*/
#define cmsXmlGetOneParameterByOID(xmlShmCb, OID,IA, parameter, value)					cmsXml_getParameterByOID(xmlShmCb, OID, IA, parameter, value)
#define cmsXmlGetOneParameterByObjPath(xmlShmCb, objPath, parameter, value)			cmsXml_getParameterByObjPath(xmlShmCb, objPath, parameter, value)
#define cmsXmlGetParameterExtAttr(xmlShmCb, objOffset, parameter)						cmsXml_getParameterExtAttr(xmlShmCb, objOffset, parameter)
#define cmsXmlGetObjectByOID(xmlShmCb, objId, objIA)									cmsXml_getObjectByOID(xmlShmCb, objId, objIA)
#define cmsXmlGetObjectByName(xmlShmCb, pathName)										cmsXml_getObjectByPathName(xmlShmCb, pathName)

/*Api for tr069*/
//#define cmsXmlGetObjParaList(xmlShmCb, objPath, nextLevel, objParaList)				cmsXml_cwmpGetObjParaList(xmlShmCb, objPath, nextLevel, objParaList)
//#define cmsXmlFreeObjParaList(objParaList)											cmsXml_cwmpFreeObjParaList(objParaList)
#define cmsXmlConstructIAValue(depth, iValue_p...)									cmsXml_ConstructIAValue(__FILE__, __FUNCTION__, __LINE__, depth, iValue_p)


/*macro for xml alloc/init/deinit*/
#define XMLSHMALLOC(preDefaultXml) cms_xmlShmAllocate(preDefaultXml)

#define XMLSHMDESTORY(xmlShm) cms_xmlShmDestory(xmlShm)

#define XMLSHMINIT() cms_xmlShmInit()
 
#define XMLSHMDEINIT(xmlShm) cms_xmlShmDeInit(&xmlShm)

#define cmsXmlGetObjRealAddr(xmlShm, offset) (offset? ((void *)(xmlShm->baseaddr + offset)):NULL)

#define XML_LOCK(lock) cmsXml_lock(lock)

#define XML_UNLOCK(lock) cmsXml_unlock(lock)

#define XMLSHM_DEFAULT_MALLOC(preDefaultXml) 	cms_xmlShm_DefAlloc(preDefaultXml)
#define XMLSHM_DEFAULT_DESTORY(defXmlShm)		cms_xmlShmDestory(defXmlShm)
#define XMLSHM_DEFAULT_INIT()					cms_xmlShm_DefInit()
#define XMLSHM_DEFAULT_DEINIT(defXmlShm)		cms_xmlShmDeInit(&defXmlShm)			
//#define _(X) (X)

/*API definition*/

/*xml shm api*/
cmsXmlCb_t *cms_xmlShmAllocate(char *preDefaultXml);
int	cms_xmlShmDestory(cmsXmlCb_t *xmlCb);
cmsXmlCb_t *cms_xmlShmInit(void);
int cms_xmlShmDeInit(cmsXmlCb_t **xmlShmCb);
cmsXmlCb_t *cms_xmlShm_DefAlloc(char *preDefaultXml);
cmsXmlCb_t *cms_xmlShm_DefInit(void);



/*create/set/free parameter list api*/
cms_multiObjSettingList_t *newMultiObjList(void);
int freeMultiObjList(cms_multiObjSettingList_t *list);
int addObjToListByName(cms_multiObjSettingList_t *pMultiObjList, char *objPath, obj_handle_type_t handleType);
int addObjToListByOID(cms_multiObjSettingList_t *pMultiObjList, uint32_t OID, uint64_t OIA, obj_handle_type_t handleType);
int setParamToMultiObjList(cms_multiObjSettingList_t *pMultiObjList, char *parameter, uint32_t type, void *value);
paraValueSettingList_t *newParameterList(void);
int setParameterToList(paraValueSettingList_t *list, const char *parameter, uint32_t type, void *value);
int freeParameterList(paraValueSettingList_t *list);


/*object api*/
cmsoffset_t cmsXmlGetPtrOffset(cmsXmlCb_t *xmlShmCb, void *ptr);
int cmsXml_getIndexChildCount(cmsXmlCb_t *xmlShmCb, cmsoffset_t id);
int cmsXml_getIndexChildStatus(cmsXmlCb_t *xmlShmCb, cmsoffset_t id);
void *cmsXml_getObjectByProtoName(cmsXmlCb_t *xmlShmCb, char *name);
void *cmsXml_getObjectByID(cmsXmlCb_t *xmlShmCb, cmsoffset_t id);
void *cmsXml_addObjectByOIDIA(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, int count, char **parameter);
void *cmsXml_addObjectByPathName(cmsXmlCb_t *xmlShmCb, char *pathName, int count, char **parameter);
void *cmsXml_addObjectByOIDWithParaList(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList);
int cmsXml_delObjectByOIDIA(cmsXmlCb_t *xmlShmCb, int OID, uint64_t objIA);
int cmsXml_delObjectByPathName(cmsXmlCb_t *xmlShmCb, char *pathName);



/*parameter direct api*/
int cmsXml_cwmpSetParameterNnotify(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList, cmsBoolean replyFlag);
int cmsXml_setParameter(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int count, char **parameter);
int cmsXml_setOneParameterByOID(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t IA, char *parameter, uint32_t type, void *value);
int cmsXml_setOneParameterByPath(cmsXmlCb_t *xmlShmCb, char *objPath, char *parameter, uint32_t type, void *value);
int cmsXml_setParameterAttr(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t flags, int active);
int cmsXml_setIndexObject(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int active);
int cmsXml_setParameterExtAttr(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint16_t flags, int active);
parameterValue_t *cmsXml_getParameter(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int count, char **parameter);
int cmsXml_getParameterByOID(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t IA, char *parameter, void *value);
int cmsXml_getParameterByObjPath(cmsXmlCb_t *xmlShmCb, char *objPath, char *parameter, void *value);
uint32_t cmsXml_getParameterAttr(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter);
uint32_t cmsXml_getParaValueType(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter);
uint16_t cmsXml_getParameterExtAttr(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter);
int cmsXml_freeParameterBuffer(parameterValue_t *pValue, int count);
int cmsXml_SaveDirect(cmsXmlCb_t *xmlShmCb);
void **cmsXml_getParameterNameByID(cmsXmlCb_t *xmlShmCb, cmsoffset_t id);
int cmsXml_freeParameterNameBuffer(void **name);
cwmp_getObjParaList_t *cmsXml_getObjParaList(cmsXmlCb_t *xmlShmCb, char *objPath, boolean nextLevel);
int	cmsXml_freeObjParaList(cwmp_getObjParaList_t *objParaList);				
int cmsXml_addObjectByOIDIWithParaList(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList);
void *cmsXml_getObjectByPathName( cmsXmlCb_t *xmlShmCb, char *pathName);
void *cmsXml_getObjectByOID( cmsXmlCb_t *xmlShmCb, uint32_t objId, uint64_t objIA);


/* parameter indirect api called by msg*/
int cmsXml_setParameterIndirectByParaList(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList);
int cmsXml_setParameterIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int count, char **parameter);
int cmsXml_setOneParameterByOIDIndirect(cmsXmlCb_t *xmlShmCb,uint32_t OID, uint64_t IA, char *parameter, uint32_t type, void *value);
int cmsXml_setOneParameterByPathIndirect(cmsXmlCb_t *xmlShmCb,char *objPath, char *parameter, uint32_t type, void *value);
int cmsXml_setParameterAttrIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t attr, int active);
int cmsXml_setParameterExtAttrIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t flags, int active);
int cmsXml_setIndexObjectIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int active);
parameterValue_t *cmsXml_getParameterIndirect(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, int count, char **parameter);
uint32_t cmsXml_getParameterAttrIndirct(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter);
uint32_t cmsXml_getParameterExtAttrIndirct(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter);
int cmsXml_SaveIndirect(cmsXmlCb_t *xmlShmCb);
int cmsXml_SaveNoReply(cmsXmlCb_t *xmlShmCb);
int cmsXml_saveToFlash(cmsXmlCb_t *xmlShmCb);
int cmsXml_saveToBak(cmsXmlCb_t *xmlShmCb);
int cmsXml_restoreConfXml(char *fileName);
int cmsXml_savePreConf(char *fileName);
int cmsXml_restoreDefaultXml(uint32_t type);
int cmsXml_ObjectStats(uint32_t OID, uint64_t IA, uint32_t timeout);
int cmsXml_addObjectByOIDIWithParaListIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList);
int cmsXml_delObjectByPathNameIndirect(cmsXmlCb_t *xmlShmCb, char *objPathName);
int cmsXml_delObjectByOIDIAIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA);
int cmsXml_addObjectByOIDIAIndirect(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, int count, char **parameter);
int cmsXml_addObjectByPathNameIndirect(cmsXmlCb_t *xmlShmCb, char *objPathName, int count, char **parameter);
int cmsXml_addObjectByPathNameWithParaList(cmsXmlCb_t *xmlShmCb, char *objPathName, paraValueSettingList_t *paraList);
void *cmsXml_objHandleByOID( cmsXmlCb_t *xmlShmCb, int OID, uint64_t objIA, int flag );
int cmsXml_setParameterNnotify(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList,cmsBoolean replyFlag);
int cmsXml_addObjectByOIDNnotify(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList, cmsBoolean replyFlag);
int cmsXml_delObjectByOIDIANnotify(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, cmsBoolean replyFlag);
int cmsXml_addObjectByPathNameNnotify(cmsXmlCb_t *xmlShmCb, char *objPathName, paraValueSettingList_t *paraList,cmsBoolean replyFlag);
int cmsXml_delObjectByPathNameNnotify(cmsXmlCb_t *xmlShmCb, char *objPathName, cmsBoolean replyFlag);
int cmsXml_setMultiObj(cmsXmlCb_t *xmlShmCb, cms_multiObjSettingList_t *pMultiObjList, cmsBoolean notifyFlag, cmsBoolean replayFlag);
int cmsXml_setParameterByOID(cmsXmlCb_t *xmlShmCb, uint32_t objID, uint64_t objIA, paraValueSettingList_t *parameterList,cmsBoolean replyFlag, uint32_t timtOut, cmsBoolean notifyFlag);


/*no msg reply api for save handle time*/
int cmsXml_addObjectByOIDIAIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, int count, char **parameter);
int cmsXml_addObjectByOIDIWithParaListIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA, paraValueSettingList_t *paraList);
int cmsXml_addObjectByPathNameIndirect_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName, int count, char **parameter);
int cmsXml_addObjectByPathNameWithParaList_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName, paraValueSettingList_t *paraList);
int cmsXml_delObjectByOIDIAIndirect_noReply(cmsXmlCb_t *xmlShmCb, uint32_t OID, uint64_t objIA);
int cmsXml_delObjectByPathNameIndirect_noReply(cmsXmlCb_t *xmlShmCb, char *objPathName);
int cmsXml_setParameterIndirect_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, int count, char **parameter);
int cmsXml_setParameterAttrIndirect_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameter, uint32_t attr, int active);
int cmsXml_setParameterIndirectByParaList_noReply(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset, paraValueSettingList_t *parameterList);


/*xml lock api*/
cmsMutexPack_t *create_mutex_package(cmsXmlCb_t	*xmlShmCb);
int destory_mutex_package(cmsXmlCb_t	 *xmlShmCb);
void cmsXml_lock(pthread_mutex_t *lock);
void cmsXml_unlock(pthread_mutex_t *lock);

/*xml encryption*/
int cmsXml_decrptConf(char *upgradeFilePath);
char *cmsXml_encryptConf(void);
int cmsXml_openSSL_Enc(const char *in,  char *out);
int cmsXml_openSSL_Dec(const char *in,  char *out);
int cmsXml_checkCurConfigCRC(void);


/*cwmp api*/
int cmsXml_cwmpSetParameterNotifyAttr(cmsXmlCb_t *xmlShmCb, char *pathName, int notifyType);
int cmsXml_cwmpGetParameterNotifyAttr(cmsXmlCb_t *xmlShmCb, char *pathName,cwmp_getParaAttrList_t **paraAttrList);
int cmsXml_cwmpFreeParaNotifyAttrList(cwmp_getParaAttrList_t *paraAttrList);
int cmsXml_cwmpSetParameterValue(cmsXmlCb_t *xmlShmCb, char *paraPathName, void *value, enum cwmp_parameterValue_type type,char *parameterKey);
int cmsXml_cwmpGetParameterValue(cmsXmlCb_t *xmlShmCb, char *paraPathName, paraValueSettingList_t **parameterList);
int cmsXml_cwmpSetParameterNotifyAttrByOID(cmsXmlCb_t *xmlShmCb,uint32_t objID,uint64_t objIA,char *paramName,int notifyType);
int cmsXml_cwmpGetParameterNotifyAttrByOID(cmsXmlCb_t *xmlShmCb, uint32_t objID,uint64_t objIA,char *paramName,cwmp_getParaAttrList_t **paraAttrList);
int cmsXml_cwmpCheckParameterValue(cmsXmlCb_t *xmlShmCb, void *object, cmsoffset_t objOff, char *parameterName, uint32_t type, char *value);

/*cwmp alarm*/
int cmsXml_add_AlarmID(char *AlarmID);
int cmsXml_del_AlarmID(char *AlarmID);
int cmsXml_save_faultcode(uint32_t fault_code, char *CommandKey, boolean needsave);


/*subcribe object*/
int cmsXml_subcribeObject(uint32_t numOfEvent, const uint32_t *eventId, uint32_t numOfObj, const uint32_t *objArray, void* (*event_rtn)(void *), void *arg);
int cmsXml_unSubcribeObject(uint32_t numOfEvent, const uint32_t *eventId, uint32_t numOfObj, const uint32_t *objArray);

/*API for dbus*/
cms_paramChgList_t *cmsXml_getChgParamList(cmsXmlCb_t *xmlShmCb, void *pNewObj, void *pOldObj);
cmsBoolean cmsXml_checkParamChg(cms_objDbusNotify_t *pObjChg, char *paramName);
void cmsXml_freeChgParamList(cms_paramChgList_t *parameterList);
cms_objDbusNotify_t *cmsXml_getChgObjInfo(char *eventContent);
void cmsXml_freeChgObjInfo(cms_objDbusNotify_t **pObjChg);
cmsBoolean cmsXml_checkobjNeedNotify(cmsXmlCb_t *xmlShmCb, uint32_t objID);


/*API for object restore*/
/*direct api*/
int cmsXml_objectRestore(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOffset);
/*indirect api*/
int cmsXml_objValueRestore(cmsXmlCb_t * xmlShmCb, uint32_t objId, uint64_t objIA, uint32_t restoreType, cmsBoolean taskNotify, cmsBoolean msgReply);

/*get object parameter value range*/
int cmsXml_getParameterValueRange(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff,char *parameterName,uint64_t *maxValue, int64_t *minValue);
/*get object parameter value type*/
int cmsXml_getParameterType(cmsXmlCb_t *xmlShmCb, cmsoffset_t objOff, char *parameterName, uint32_t *type);


/*obj IA api*/
uint64_t cmsXml_ConstructIAValue(const char *fileName, const char *funcName, const int lineNo, uint8_t depth, char* iValue_p, ...);

/*record cms key infor*/
void cms_log_record(char *logInfo);
void cms_log_backUp(void);

int cmsSetLogLevel(cmsMsg_action_t *pAction, char *name);
#if 0
int cmsSetL2Mode5Tuple(uint32_t en);
#endif


#endif /* end of include guard: __LIBMDM_3J4BCHU9 */
